package com.manage.server.controller.admin;

import com.manage.dto.LocationDTO;
import com.manage.dto.add.LocationAddDTO;
import com.manage.dto.update.LocationUpdateDTO;
import com.manage.result.PageResult;
import com.manage.server.service.LocationService;
import com.manage.vo.LocationVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.manage.result.Result;

@RestController
@RequestMapping("/location")
public class LocationController {

    @Autowired
    private LocationService locationService;

    @PostMapping
    public Result add(@RequestBody LocationAddDTO locationAddDTO) {
        locationService.save(locationAddDTO);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        locationService.removeById(id);
        return Result.success();
    }

    @PutMapping
    public Result update(@RequestBody LocationUpdateDTO locationUpdateDTO) {
        locationService.updateById(locationUpdateDTO);
        return Result.success();
    }

    /**
     * Paginated search with multiple filters
     * @param locationDTO
     * @return
     */
    @PostMapping("/page")
    public PageResult<LocationVO> findLocation(@RequestBody LocationDTO locationDTO) {
        return locationService.findLocationByPage(locationDTO);
    }
}